﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using d1Common.WebController;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using d1Common;
using d1Project.Modules.Common.do4A.Domain;
using d1Project.Modules.Common.do4A.Models;

namespace d1Project.Modules.Common.do4A.Controllers.a2
{
    [Route("do4A/a2/ThirdPartToken")]
    public class ThirdPartToken2Controller : ControllerBase
    {
        protected override DbContext dbContext
        {
            get
            {
                return this.db;
            }
        }
        private do4ADbContext db = new do4ADbContext();
        public async Task<IHttpActionResult> Get([FromUri]ThirdPartTokenVm model)
        {
            string _accessToken = await ThirdPartAuthenticationMgr.Instance.getAccessToken(this.db, model.AppType, model.AppCode, model.AppOpenId, model.AppAccessToken);
            return Ok(new { accessToken = _accessToken });
        }
        public class ThirdPartTokenVm
        {
            /// <summary>
            /// 第三方认证的类型（WeiXin 微信、QQ 腾讯qq、SinaWeiBo 微博）
            /// </summary>
            public string AppType { get; set; }

            /// <summary>
            /// 第三方应用的Code
            /// </summary>
            public string AppCode { get; set; }

            /// <summary>
            /// 第三方应用的OpenId
            /// </summary>
            public string AppOpenId { get; set; }

            /// <summary>
            /// 第三方应用的AccessToken
            /// </summary>
            public string AppAccessToken { get; set; }

        }
    }
}